#include <iostream>

using namespace std;

// const int NUM_CNT = 5;

void sort(int arr[], int size){
	if(size <= 1)
		return;

	int negCnt = 0;
	for(int i = 0; i < size; ++i){
		if(arr[i] < 0)
			negCnt++;
	}

	int begin = 0, end = size - 1;
	int oIndex = negCnt - 1;

	while(begin < end && oIndex < end){
		if(arr[begin] < 0)
			++begin;
		else if(arr[begin] == 0){
			while(arr[oIndex] == 0 && begin < end)
				++oIndex;
			if(begin >= end)
				return ;
			arr[begin] = arr[oIndex];
			arr[oIndex] = 0;
			++oIndex;
		}
		else{
			while(arr[end] > 0 && begin < end)
				--end;
			if(begin >= end)
				return ;
			if(arr[end] == 0){
				arr[end] = arr[oIndex];
				arr[oIndex] = 0;
				++oIndex;
				continue;
			}
			arr[begin] ^= arr[end];
			arr[end] ^= arr[begin];
			arr[begin] ^= arr[end];
			++begin;
			--end;
		}
	}
	return;
}

void sort(int arr[], int size, bool b){
	if(size <= 1)
		return;
	
	int begin = 0, end = size - 1;
	int oleft = -1, oright = size;

	while(begin <= end){
		if(arr[begin] < 0){
			if(oleft != begin && oleft != -1){
				arr[oleft++] = arr[begin];
				arr[begin] = 0;
			}
			++begin;
		}
		else if(arr[begin] == 0){
			if(oleft == -1)
				oleft = begin;
			++begin;
		}
		else{ // arr[begin] > 0
			while(begin <= end){
				if(arr[end] > 0){
					if(oright != end && oright != size){
						arr[oright--] = arr[end];
						arr[end] = 0;
					}
					--end;
				}
				else if(arr[end] == 0){
					if(oright == size)
						oright = end;
					 --end;
				}
				else{ // arr[end] < 0
					arr[begin] ^= arr[end];
					arr[end] ^= arr[begin];
					arr[begin] ^= arr[end];

					if(oright != end && oright != size){
						arr[oright--] = arr[end];
						arr[end] = 0;
					}

					break;					
				}
			}
		}
	}

	return;
}

int *sort(int arr[], int beginIndex, int endIndex){
	int temp = 0;
	while(beginIndex < endIndex){
		if(arr[beginIndex] < 0){
			++beginIndex;
		}
		else if(arr[beginIndex] == 0){
			if(arr[beginIndex] > arr[endIndex]){
				
			}
		}
		else{

		}
	}
	return NULL;
}


int fnc(int number){
	number & 0x80000000 && (number = number ^ 0xffffffff, number += 1);

	return number;
}

int fnc1(int number){
	/*
	int result = number;
	result = number & 0x7fffffff;

	result ^ number;
*/
	// (number ^ (number & 0x7fffffff) ^ 0x80000000) && (number = (number ^ 0x7fffffff) | 0x8fffffff + 1); //error:  + 1 by bit??
	// (number ^ (number & 0x7fffffff) ^ 0x80000000) && (number = ~number + 1);
	// (number ^ (number & 0x7fffffff) ^ 0x80000000) && (number = number ^ 0x7fffffff, number += 1, number |= 0x80000000);
	// ~(number | 0x7fffffff) && (number = number ^ 0x7fffffff, number += 1, number |= 0x80000000);

	return number;
}

int fnc2(int number){
	if(number < 0)
		number *= -1;
	return number;
}

int main(){

	int i = fnc(-10);
	int j = fnc1(10);
	int j2 = fnc1(-10);

	int arr[] = {0, 0, -10, 3, 5, 0, -1, 0, -1, 1, 0, 0, 2, 2, 10, 0, 0, -10, 3, 5, 0, -1, 0, -1, 1, 0, 0, -1, 0, 0};
	// int arr[] = {10, -10};

	sort(arr, sizeof(arr) / sizeof(arr[0]), false);

	return 0;
}

